package it.univaq.mwt.facade;

import java.io.IOException;

import it.univaq.mwt.business.ListService;
import it.univaq.mwt.exceptionmonitor.LivelloEx;
import it.univaq.mwt.exceptionmonitor.WishListrException;
import it.univaq.mwt.exceptionmonitor.WishlistUserException;
import it.univaq.mwt.exceptionmonitor.WishlistrMessage;
import it.univaq.mwt.log.LivelloLog;
import it.univaq.mwt.log.LogManager;
import it.univaq.mwt.model.bean.ListBeanRemote;
import it.univaq.mwt.model.entity.Lists;


public class FacadeList implements ListService,LivelloEx, LivelloLog {


	private ListBeanRemote lbr;
	public FacadeList(ListBeanRemote lbr) {
		super();
		this.lbr = lbr;
	}
	
	
	public void addLists(String name, int id_user) throws WishlistUserException {
		
		try{
			try {
				lbr.createList(name, id_user);
			} catch (WishlistrMessage e) {
				LogManager.getIstance().scrivi("FacadeNews - deleteNews " + e.getMessage(), ERR);
				//throw
			}

			LogManager.getIstance().scrivi("FacadeList - addLists: Richiesta aggiunta della lista " + name, RUN);
		} catch (IOException e) {
			new WishListrException(e,ERROR);
		}
	}
	
	
	public Lists getLists(int id_user) {
		Lists lists=null;
		
		try{
			try {
				lists=lbr.getLists(id_user);
			} catch (WishlistrMessage e) {
				LogManager.getIstance().scrivi("FacadeNews - getLists :" + e.getMessage(), ERR);
				//throw
			}

			LogManager.getIstance().scrivi("FacadeList - getLists : Richiesta la lista dell'utente con id " + id_user, RUN);
		} catch (IOException e) {
			new WishListrException(e,ERROR);
		}
		return lists;
	}



	
	public void editLists(String name, int id_list) throws WishlistUserException {

			try{
				try {
					lbr.editList(name, id_list);
				} catch (WishlistrMessage e) {
					LogManager.getIstance().scrivi("FacadeNews - deleteNews " + e.getMessage(), ERR);
					//throws
				}

				LogManager.getIstance().scrivi("FacadeList - editLists: Modifica della lista con id " + id_list, RUN);
			} catch (IOException e) {
				new WishListrException(e,ERROR);
			}
	}	
}